using System;
using System.Text;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using OVS.BusinessObjects;

namespace OVS.DAL
{
	public partial class Image_HaarDAO
	{
		public Image_HaarDAO()
		{
			DbProviderHelper.GetConnection();
		}
		public List<Image_Haar> GetImage_Haars()
		{
			try
			{
				List<Image_Haar> lstImage_Haars = new List<Image_Haar>();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [imha_id],[imha_fn],[imha_label],[imha_height],[imha_width],[imha_desc],[imha_scaleFactor],[imha_minNeighbors] FROM [Image_Haar]",CommandType.Text);
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					Image_Haar oImage_Haar = new Image_Haar();
					oImage_Haar.imha_id = Convert.ToInt32(oDbDataReader["imha_id"]);
					oImage_Haar.imha_fn = Convert.ToString(oDbDataReader["imha_fn"]);

					if(oDbDataReader["imha_label"] != DBNull.Value)
						oImage_Haar.imha_label = Convert.ToString(oDbDataReader["imha_label"]);

					if(oDbDataReader["imha_height"] != DBNull.Value)
						oImage_Haar.imha_height = Convert.ToInt32(oDbDataReader["imha_height"]);

					if(oDbDataReader["imha_width"] != DBNull.Value)
						oImage_Haar.imha_width = Convert.ToInt32(oDbDataReader["imha_width"]);

					if(oDbDataReader["imha_desc"] != DBNull.Value)
						oImage_Haar.imha_desc = Convert.ToString(oDbDataReader["imha_desc"]);

					if(oDbDataReader["imha_scaleFactor"] != DBNull.Value)
						oImage_Haar.imha_scaleFactor = Convert.ToDouble(oDbDataReader["imha_scaleFactor"]);

					if(oDbDataReader["imha_minNeighbors"] != DBNull.Value)
						oImage_Haar.imha_minNeighbors = Convert.ToDouble(oDbDataReader["imha_minNeighbors"]);
					lstImage_Haars.Add(oImage_Haar);
				}
				oDbDataReader.Close();
				return lstImage_Haars;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public Image_Haar GetImage_Haar(int imha_id)
		{
			try
			{
				Image_Haar oImage_Haar = new Image_Haar();
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [imha_id],[imha_fn],[imha_label],[imha_height],[imha_width],[imha_desc],[imha_scaleFactor],[imha_minNeighbors] FROM [Image_Haar] WHERE [imha_id]=@imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_id",DbType.Int32,imha_id));
				DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
				while (oDbDataReader.Read())
				{
					oImage_Haar.imha_id = Convert.ToInt32(oDbDataReader["imha_id"]);
					oImage_Haar.imha_fn = Convert.ToString(oDbDataReader["imha_fn"]);

					if(oDbDataReader["imha_label"] != DBNull.Value)
						oImage_Haar.imha_label = Convert.ToString(oDbDataReader["imha_label"]);

					if(oDbDataReader["imha_height"] != DBNull.Value)
						oImage_Haar.imha_height = Convert.ToInt32(oDbDataReader["imha_height"]);

					if(oDbDataReader["imha_width"] != DBNull.Value)
						oImage_Haar.imha_width = Convert.ToInt32(oDbDataReader["imha_width"]);

					if(oDbDataReader["imha_desc"] != DBNull.Value)
						oImage_Haar.imha_desc = Convert.ToString(oDbDataReader["imha_desc"]);

					if(oDbDataReader["imha_scaleFactor"] != DBNull.Value)
						oImage_Haar.imha_scaleFactor = Convert.ToDouble(oDbDataReader["imha_scaleFactor"]);

					if(oDbDataReader["imha_minNeighbors"] != DBNull.Value)
						oImage_Haar.imha_minNeighbors = Convert.ToDouble(oDbDataReader["imha_minNeighbors"]);
				}
				oDbDataReader.Close();
				return oImage_Haar;
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int AddImage_Haar(Image_Haar oImage_Haar)
		{
			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Image_Haar]([imha_fn],[imha_label],[imha_height],[imha_width],[imha_desc],[imha_scaleFactor],[imha_minNeighbors])VALUES(@imha_fn,@imha_label,@imha_height,@imha_width,@imha_desc,@imha_scaleFactor,@imha_minNeighbors);SELECT SCOPE_IDENTITY();",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_fn",DbType.String,oImage_Haar.imha_fn));
				if (oImage_Haar.imha_label!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_label",DbType.String,oImage_Haar.imha_label));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_label",DbType.String,DBNull.Value));
				if (oImage_Haar.imha_height.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_height",DbType.Int32,oImage_Haar.imha_height));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_height",DbType.Int32,DBNull.Value));
				if (oImage_Haar.imha_width.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_width",DbType.Int32,oImage_Haar.imha_width));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_width",DbType.Int32,DBNull.Value));
				if (oImage_Haar.imha_desc!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_desc",DbType.String,oImage_Haar.imha_desc));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_desc",DbType.String,DBNull.Value));
				if (oImage_Haar.imha_scaleFactor.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_scaleFactor",DbType.Double,oImage_Haar.imha_scaleFactor));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_scaleFactor",DbType.Double,DBNull.Value));
				if (oImage_Haar.imha_minNeighbors.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_minNeighbors",DbType.Double,oImage_Haar.imha_minNeighbors));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_minNeighbors",DbType.Double,DBNull.Value));

				return Convert.ToInt32(DbProviderHelper.ExecuteScalar(oDbCommand));
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int UpdateImage_Haar(Image_Haar oImage_Haar)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Image_Haar] SET [imha_fn]=@imha_fn,[imha_label]=@imha_label,[imha_height]=@imha_height,[imha_width]=@imha_width,[imha_desc]=@imha_desc,[imha_scaleFactor]=@imha_scaleFactor,[imha_minNeighbors]=@imha_minNeighbors WHERE [imha_id]=@imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_fn",DbType.String,oImage_Haar.imha_fn));
				if (oImage_Haar.imha_label!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_label",DbType.String,oImage_Haar.imha_label));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_label",DbType.String,DBNull.Value));
				if (oImage_Haar.imha_height.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_height",DbType.Int32,oImage_Haar.imha_height));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_height",DbType.Int32,DBNull.Value));
				if (oImage_Haar.imha_width.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_width",DbType.Int32,oImage_Haar.imha_width));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_width",DbType.Int32,DBNull.Value));
				if (oImage_Haar.imha_desc!=null)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_desc",DbType.String,oImage_Haar.imha_desc));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_desc",DbType.String,DBNull.Value));
				if (oImage_Haar.imha_scaleFactor.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_scaleFactor",DbType.Double,oImage_Haar.imha_scaleFactor));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_scaleFactor",DbType.Double,DBNull.Value));
				if (oImage_Haar.imha_minNeighbors.HasValue)
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_minNeighbors",DbType.Double,oImage_Haar.imha_minNeighbors));
				else
					oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_minNeighbors",DbType.Double,DBNull.Value));
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_id",DbType.Int32,oImage_Haar.imha_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveImage_Haar(Image_Haar oImage_Haar)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Image_Haar] WHERE [imha_id]=@imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_id",DbType.Int32,oImage_Haar.imha_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		public int RemoveImage_Haar(int imha_id)
		{

			try
			{
				DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Image_Haar] WHERE [imha_id]=@imha_id",CommandType.Text);
				oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@imha_id",DbType.Int32,imha_id));
				return DbProviderHelper.ExecuteNonQuery(oDbCommand);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
	}
}
